import { createRouter, createWebHistory } from "vue-router";
import { h } from "vue";
import one from "../page/one.vue";
import view from "../components/routerView.vue";
const router = createRouter({
  history: createWebHistory(),
  routes: [
    {
      path: "/",
      component: one,
      children: [
        {
          path: "/child",
          component: () => import("../page/onechild/index.vue"),
        },
      ],
    },
    {
      path: "/two",
      component: () => import("../page/two.vue"),
      children: [
        {
          path: "/child1",
          component: () => import("../page/twochild/index.vue"),
        },
      ],
    },
    {
      path: "/use",
      component: view,
      redirect: "vue",
      children: [
        {
          path: "/vue",
          component: () => import("../page/vueuse/index.vue"),
        },
      ],
    },
  ],
  scrollBehavior: function (to, from, saved) {
    // return {saved.top,saved.left}
    if (saved) {
      return saved;
    } else {
      return { top: 0, left: 10 };
    }
  },
});
router.addRoute({
  path: "/h",
  component: {
    render: function () {
      return h("div", {}, [123, h("span", {}, "as")]);
    },
  },
});

export default router;
